﻿package mortal.game.view.business
{
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class TradeSelectNumWin extends SmallWindow
    {
        private var _textField:GTextFiled;
        private var _textInput:GTextInput;
        private var _btnOK:GButton;
        private var _btnCancel:GButton;
        private static var _instance:TradeSelectNumWin;

        public function TradeSelectNumWin(param1:ILayer = null)
        {
            super(param1);
            this.setSize(280, 210);
            if (_instance != null)
            {
                throw new Error(" TradeSelectNumWin 单例 ");
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._textField = UIFactory.gTextField("", 75, 67, 150, 20, this, null, true);
            this._textField.text = Language.getString(21351);
            this._textInput = UIFactory.gTextInput(80, 93, 133, 24, this);
            this._textInput.restrict = "0-9";
            this._textInput.text = "1";
            this._textInput.configEventListener(Event.CHANGE, this.onInputChange);
            this._btnOK = UIFactory.gButton(Language.getString(30026), 75, 180, 47, 22, this);
            this._btnOK.configEventListener(MouseEvent.CLICK, this.SplitHandler);
            this._btnCancel = UIFactory.gButton(Language.getString(30027), 175, 180, 47, 22, this);
            this._btnCancel.configEventListener(MouseEvent.CLICK, this.CloseHandler);
            this.updateViewByData();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._textField.dispose(param1);
            this._textInput.dispose(param1);
            this._btnOK.dispose(param1);
            this._btnCancel.dispose(param1);
            this._textField = null;
            this._textInput = null;
            this._btnOK = null;
            this._btnCancel = null;
            return;
        }// end function

        public function updateViewByData() : void
        {
            this._textInput.text = TradeModule._selectingNumItem.itemAmount.toString();
            return;
        }// end function

        private function onInputChange(event:Event) : void
        {
            if (TradeModule._selectingNumItem == null)
            {
                return;
            }
            if (this._textInput.text == "")
            {
                return;
            }
            if (int(this._textInput.text) > TradeModule._selectingNumItem.itemAmount)
            {
                this._textInput.text = TradeModule._selectingNumItem.itemAmount.toString();
            }
            if (int(this._textInput.text) < 1)
            {
                this._textInput.text = "1";
            }
            return;
        }// end function

        private function SplitHandler(event:MouseEvent) : void
        {
            var _loc_2:* = int(this._textInput.text);
            if (TradeModule._selectingNumItem == null)
            {
                this.hide();
                return;
            }
            if (_loc_2 > 0 && _loc_2 <= TradeModule._selectingNumItem.serverData.itemAmount)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TradeSelectNumOver, _loc_2));
                this.hide();
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(21352));
            }
            return;
        }// end function

        private function CloseHandler(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        public static function get instance() : TradeSelectNumWin
        {
            if (_instance == null)
            {
                _instance = new TradeSelectNumWin;
            }
            return _instance;
        }// end function

    }
}
